/**
 * Created by shudong.msd(风骐) on 2016/4/17.
 */


"use strict";

app.controller('navCtrl',['$scope','$http','$rootScope','$interval','$state',function($scope,$http,$rootScope,$interval,$state){

    var comutil = new commUtils();

    $scope.$on('$viewContentLoaded', function() {
        //固定导航栏
        angular.element('.mz-left-nav').stickUp();

        /*$('.mz-left-nav').setScroll({
            parentContrainer:$('body'),
            gap: 0,
            prevBoxs:[]
        });*/
        angular.element(".mz-left-nav ").css("height",innerHeight);


        //未读任务提示
        angular.element(".mz-left-nav>li").unbind('click');
        angular.element(".mz-left-nav>li").bind('click',function(event){
            //更换动画
            //$rootScope.updateAnimate();
            angular.element(".mz-left-nav ").css("height",innerHeight);
            updateStatusOfUnread($('.redDot'));
        });

        updateStatusOfUnread($('.redDot'));

    });

    var updateStatusOfUnread = function(obj){
        $http.get(UrlMappings.UNREAD_COUNT, {
            params: {
                'access_token': comutil.getTocken()
            },
            header: {
                'Accept': 'application/json',
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }).success(function (data) {
            if (data['recordCount'] > 0) {
                obj.show();
            } else {
                obj.hide();
            }

        }).error(function(data,status){
            if(status=='401')comutil.logout($state);
        });

    };

    function sleep(d){
        for(var t = Date.now();Date.now() - t <= d;);
    }


}]);